Branchwell

AI Resource Pro / website · airesourcepro.com / src / app / [track] / [slug] / page.tsx

1import type { Metadata } from "next";
2import Image from "next/image";
3import Link from "next/link";
4import { notFound } from "next/navigation";
5import { MDXRemote } from "next-mdx-remote/rsc";
6import { CalendarDays, Clock, Gauge, ListOrdered, RefreshCw } from "lucide-react";
7import remarkGfm from "remark-gfm";
8import { mdxComponents, OwnedVideo } from "@/components/mdx/mdx-components";
9import { RevealOnScroll } from "@/components/reveal-on-scroll";
10import { RecordTutorialView } from "@/components/record-tutorial-view";
11import { SaveTutorialButton } from "@/components/save-tutorial-button";
12import ShareButton from "@/components/share-button";
13import { ReadingProgress } from "@/components/tutorial/reading-progress";
14import { InlineTableOfContents, TableOfContents } from "@/components/tutorial/table-of-contents";
15import { VideoComingSoon } from "@/components/tutorial/video-coming-soon";
16import { DraftBadge, TutorialGrid } from "@/components/tutorial-card";
17import { JsonLd } from "@/components/json-ld";
18import { AUTHOR, breadcrumbJsonLd, ogImageFor, pageMetadata, tutorialJsonLd } from "@/lib/seo";
19import { getTrack } from "@/lib/tracks";
20import { getAllTutorials, getTutorial, getTutorialMetas, getTutorialsByTrack, tutorialKey } from "@/lib/tutorials";
21import { cn } from "@/lib/utils";
22
23export const dynamicParams = false;
24
25export function generateStaticParams() {
26 return getAllTutorials().map((t) => ({ track: t.track, slug: t.slug }));
27}
28
29type Props = { params: Promise<{ track: string; slug: string }> };
30
31export async function generateMetadata({ params }: Props): Promise<Metadata> {
32 const { track, slug } = await params;
33 const tutorial = getTutorial(track, slug);
34 if (!tutorial) return {};
35 return pageMetadata({
36 title: tutorial.title,
37 description: tutorial.description,
38 path: `/${tutorial.track}/${tutorial.slug}`,
39 image: ogImageFor(tutorial.cover),
40 type: "article",
41 publishedTime: tutorial.publishedAt || undefined,
42 modifiedTime: tutorial.updatedAt,
43 // Drafts stay out of search results until they're finished
44 noindex: tutorial.draft,
45 });
46}
47
48const sideHeading = "mb-4 block font-mono text-xs font-medium uppercase tracking-[0.08em]";
49const chip =
50 "inline-flex items-center gap-1.5 rounded-full border border-border bg-card px-3 py-1.5 font-mono text-[11px] uppercase tracking-[0.08em] text-[var(--mist)]";
51
52export default async function TutorialPage({ params }: Props) {
53 const { track: trackSlug, slug } = await params;
54 const tutorial = getTutorial(trackSlug, slug);
55 const track = getTrack(trackSlug);
56 if (!tutorial || !track) notFound();
57 const siblings = getTutorialsByTrack(track.slug);
58 const sections = tutorial.headings.filter((h) => h.depth === 2).length;
59 // Same track first, then the newest from other tracks
60 const more = [
61 ...siblings.filter((t) => t.slug !== tutorial.slug),
62 ...getTutorialMetas().filter((t) => t.track !== track.slug),
63 ].slice(0, 3);
64
65 return (
66 <div className="page" id="top" style={{ "--tc": track.color } as React.CSSProperties}>
67 <JsonLd
68 data={[
69 ...tutorialJsonLd(tutorial, track),
70 breadcrumbJsonLd([
71 { name: "Home", path: "/" },
72 { name: track.name, path: `/${track.slug}` },
73 { name: tutorial.title, path: `/${tutorial.track}/${tutorial.slug}` },
74 ]),
75 ]}
76 />
77 <ReadingProgress />
78 <RevealOnScroll selector=".tutorial-prose > *, [data-reveal]" />
79
80 <header className="grid items-center gap-8 overflow-hidden rounded-3xl border border-border bg-card p-4 sm:p-6 lg:grid-cols-[minmax(0,1fr)_minmax(0,0.95fr)] lg:gap-10 lg:p-8">
81 <div className="p-2 sm:p-4 lg:p-6">
82 <Link href={`/${track.slug}`} className="label w-fit hover:underline hover:underline-offset-4">
83 <i />
84 {track.name}
85 </Link>
86 <h1 className="display-title mt-6 text-[clamp(32px,3.4vw,52px)]">{tutorial.title}</h1>
87 <p className="mt-5 max-w-2xl text-[clamp(17px,1.35vw,20px)] leading-relaxed text-[var(--mist)]">{tutorial.description}</p>
88 <div className="mt-8 flex flex-wrap items-center gap-2">
89 <span className={chip}>
90 <Gauge className="h-3.5 w-3.5" /> {tutorial.level}
91 </span>
92 <span className={chip}>
93 <Clock className="h-3.5 w-3.5" /> {tutorial.minutes} min {tutorial.video ? "watch" : "read"}
94 </span>
95 {sections > 0 && (
96 <span className={chip}>
97 <ListOrdered className="h-3.5 w-3.5" /> {sections} sections
98 </span>
99 )}
100 {tutorial.publishedAt && (
101 <span className={chip}>
102 <CalendarDays className="h-3.5 w-3.5" /> {tutorial.publishedAt}
103 </span>
104 )}
105 {tutorial.updatedAt && tutorial.updatedAt !== tutorial.publishedAt && (
106 <span className={chip}>
107 <RefreshCw className="h-3.5 w-3.5" /> Updated {tutorial.updatedAt}
108 </span>
109 )}
110 {tutorial.draft && <DraftBadge />}
111 </div>
112 <div className="mt-8 flex flex-wrap items-center gap-x-6 gap-y-4">
113 <SaveTutorialButton tutorialKey={tutorialKey(tutorial)} />
114 <ShareButton small className="airp-share" title={tutorial.title} text="A hands-on AI tutorial from AI Resource Pro." />
115 <RecordTutorialView tutorialKey={tutorialKey(tutorial)} />
116 <Link href={AUTHOR.path} rel="author" className="group flex items-center gap-3 text-sm text-[var(--mist)]">
117 <Image src={AUTHOR.photo} alt="" width={36} height={36} className="h-9 w-9 rounded-lg object-cover" />
118 <span>
119 By <span className="text-foreground group-hover:underline group-hover:underline-offset-4">{AUTHOR.name}</span>
120 </span>
121 </Link>
122 </div>
123 </div>
124 <div className="relative aspect-[5/3] overflow-hidden rounded-2xl border border-border shadow-[0_30px_80px_-30px_var(--card-glow)] max-lg:order-first">
125 <Image src={tutorial.cover} alt="" fill priority sizes="(min-width: 1024px) 640px, 100vw" className="object-cover" />
126 </div>
127 </header>
128
129 <div className="mt-14 grid gap-12 lg:grid-cols-[220px_minmax(0,1fr)] xl:grid-cols-[220px_minmax(0,1fr)_250px]">
130 <aside className="hidden lg:block">
131 <nav aria-label={`${track.name} tutorials`} className="sticky top-32 space-y-1 text-sm">
132 <Link href={`/${track.slug}`} className={cn(sideHeading, "text-[var(--tc)] hover:underline hover:underline-offset-4")}>
133 {track.name} tutorials
134 </Link>
135 {siblings.map((s) => (
136 <Link
137 key={s.slug}
138 href={`/${s.track}/${s.slug}`}
139 aria-current={s.slug === tutorial.slug ? "page" : undefined}
140 className={cn(
141 "block border-l-2 py-1.5 pl-3 leading-snug transition-colors",
142 s.slug === tutorial.slug
143 ? "border-[var(--tc)] text-foreground"
144 : "border-border text-[var(--link)] hover:border-[var(--link)] hover:underline hover:underline-offset-4"
145 )}
146 >
147 {s.title}
148 </Link>
149 ))}
150 </nav>
151 </aside>
152
153 <article className="min-w-0 max-w-3xl">
154 {tutorial.headings.length > 0 && <InlineTableOfContents headings={tutorial.headings} />}
155 {tutorial.video ? (
156 <OwnedVideo id={tutorial.video} title={tutorial.title} captions={tutorial.videoCaptions} />
157 ) : (
158 tutorial.videoComingSoon && <VideoComingSoon />
159 )}
160 <div className="tutorial-prose mt-10">
161 <MDXRemote source={tutorial.body} components={mdxComponents} options={{ mdxOptions: { remarkPlugins: [remarkGfm] } }} />
162 </div>
163 </article>
164
165 {tutorial.headings.length > 0 && (
166 <aside className="hidden xl:block">
167 <div className="sticky top-28">
168 <TableOfContents headings={tutorial.headings} />
169 </div>
170 </aside>
171 )}
172 </div>
173
174 {more.length > 0 && (
175 <section className="mt-28 border-t border-border pt-14" data-reveal>
176 <h2 className="label mb-8">
177 <i />
178 Keep going
179 </h2>
180 <TutorialGrid tutorials={more} />
181 </section>
182 )}
183 </div>
184 );
185}